#!/bin/sh

# Set mctpi2c/mctpi3c link up and assign local address.
localEid=8

# shellcheck source=meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
. /usr/libexec/yosemite4-common-functions

busnum=0
# Enable MCTP-I3C for BMC
# The Sentinel Dome BICs are after the I3C hub on I3C bus0 and bus1.
while [ $busnum -le 1 ]
do
    for i in $(seq 1 4); do
        slot=$((busnum * 4 + i))
        eidBase=$((slot * 10))
        lladdr=$(printf "0x07:ec:80:01:00:%02x" $(((slot - 1) * 5)))
        mctp route add $((eidBase + 0)) via mctpi3c${busnum}
        mctp route add $((eidBase + 2)) via mctpi3c${busnum}
        mctp route add $((eidBase + 4)) via mctpi3c${busnum}
        mctp route add $((eidBase + 5)) via mctpi3c${busnum}
        mctp neigh add $((eidBase + 0)) dev mctpi3c${busnum} lladdr "$lladdr"
        mctp neigh add $((eidBase + 2)) dev mctpi3c${busnum} lladdr "$lladdr"
        mctp neigh add $((eidBase + 4)) dev mctpi3c${busnum} lladdr "$lladdr"
        mctp neigh add $((eidBase + 5)) dev mctpi3c${busnum} lladdr "$lladdr"
    done
    mctp link set mctpi3c${busnum} up
    mctp addr add ${localEid} dev mctpi3c${busnum}
    busnum=$((busnum+1))
done

# The NICs are on the i2c bus24 to bus27.
# Set the MTU to ETH_MIN_MTU, in range.

busnum=24
while [ $busnum -le 27 ]
do
    mctp link set mctpi2c${busnum} up
    mctp link set mctpi2c${busnum} mtu 68
    mctp addr add ${localEid} dev mctpi2c${busnum}
    busnum=$((busnum+1))
done
